//
//  CarDetailCell.m
//  HeWeiZhiNeng
//
//  Created by 林建 on 2017/12/17.
//  Copyright © 2017年 YanCeyMichael.github.io. All rights reserved.
//

#import "CarDetailCell.h"
@interface CarDetailCell()
@property (nonatomic, strong)UIImageView *headImage;
@property (nonatomic, strong)UILabel *titleLabel;
@property (nonatomic, strong)UILabel *contentLabel;
@end

@implementation CarDetailCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

-(void)setModel:(CellModel *)model{
    if ([model.type isEqualToString:@"image"]) {
        self.headImage.image = [UIImage imageNamed:@"sy_chetoxiang_img"];
        [self.headImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.mas_centerX);
            make.centerY.mas_equalTo(self.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(90, 90));
        }];
    } else if ([model.type isEqualToString:@"text"]) {
        self.titleLabel.text = model.title;
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top);
            make.leading.mas_equalTo(self.mas_leading).offset(15);
            make.size.mas_equalTo(CGSizeMake(80, 44));
        }];
        self.contentLabel.text = model.content;
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top);
            make.leading.mas_equalTo(self.titleLabel.mas_trailing).offset(30);
            make.trailing.mas_equalTo(self.mas_trailing).offset(-15);
            make.bottom.mas_equalTo(self.mas_bottom);
        }];
    } else if ([model.type isEqualToString:@"button"]) {
        self.titleLabel.text = model.title;
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top);
            make.leading.mas_equalTo(self.mas_leading).offset(15);
            make.trailing.mas_equalTo(self.mas_trailing).offset(-15);
            make.bottom.mas_equalTo(self.mas_bottom);
        }];
    }
}

#pragma mark ----- 头像 -----
-(UIImageView *)headImage{
    if (!_headImage) {
        _headImage = [[UIImageView alloc]init];
        [self.contentView addSubview:_headImage];
        _headImage.layer.cornerRadius = 45;
        _headImage.layer.masksToBounds = YES;
    }
    return _headImage;
}

#pragma mark ----- 标题 -----
-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = Color.theme;
        _titleLabel.font = Common_Font(15);
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

#pragma mark ----- 内容 -----
-(UILabel *)contentLabel{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc]init];
        _contentLabel.textColor = Color.theme;
        _contentLabel.font = Common_Font(15);
        [self.contentView addSubview:_contentLabel];
    }
    return _contentLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
